#include <iostream>
#include <algorithm>
#include <cstring>
#include <string>
#include <map>
#include <vector>


//2维前缀和
using namespace std;
using LL = long long;
const int N = 1010;

int n, q;
LL pre[N][N];

void solve(){
    memset(pre, 0, sizeof pre);
    scanf("%d%d", &n, &q);

    int h, w;
    for(int i = 0; i < n; i ++){
        scanf("%d%d", &h, &w);
        pre[h][w] = (LL)h * w + pre[h][w];
    }

    for(int i = 1; i <= 1000; i ++){
        for(int j = 1; j <= 1000; j ++){
            pre[i][j] = pre[i - 1][j] + pre[i][j - 1] - pre[i - 1][j - 1] + pre[i][j];
        }
    }

    int h1, w1, h2, w2;
    LL res = 0;
    while(q --){
        scanf("%d%d%d%d", &h1, &w1, &h2, &w2);

        res = pre[h2 - 1][w2 - 1] - pre[h1][w2 - 1] - pre[h2 - 1][w1] + pre[h1][w1];
        if(res < 0) res = 0;
        printf("%lld\n", res);
    }
}

int main(){
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);

    int T;
    scanf("%d", &T);
    while(T--){
        solve();
    }
    return 0;
}